import { defineStore } from 'pinia'
import { ref } from 'vue'
import { UserInfo, BreadItem, personInfo } from './main.d'

export const useMainStore = defineStore(
  'main', // id
  () => {
    // 样例
    const count = ref(0)
    // 用户集合
    const userList = ref<UserInfo[]>([])
    // 用户
    const userInfo = ref<personInfo>({
      anqxList: [],
      bmbm: '',
      bmmc: '',
      dwbm: '',
      dwmc: '',
      cdqxList: [],
      headpic: '',
      rybm: '',
      ryid: '',
      rymc: '',
      sfzh: '',
      token: '',
      tyywid: '',
      xm: '',
      mc: '',
      dzyx: '',
      dhhm: '',
      sjly: '',
    })
    //面包屑
    const breadData = ref<BreadItem[]>([])

    const nodeTreeData = ref()

    const jzsmDbmNode = ref()

    const jzsmZpNode = ref()

    const zjNode = ref()

    const fjNode = ref()

    const prePage = ref('')
    // 保存用户信息
    const saveUserInfo = (data: personInfo) => {
      userInfo.value = data
    }

    // 修改面包屑
    const saveBreadData = (data: BreadItem[]) => {
      breadData.value = data
    }

    // 存储点击的每一个树节点
    const saveNodeTreeData = (data: any) => {
      nodeTreeData.value = data
    }

    // 存储正卷节点
    const saveZjNode = (data: any) => {
      zjNode.value = data
    }

    // 存储副卷节点
    const saveFjNode = (data: any) => {
      fjNode.value = data
    }

    // 存储集中扫描待编目材料节点
    const saveJzsmDbmNode = (data: any) => {
      jzsmDbmNode.value = data
    }

    // 存储集中扫描照片节点
    const saveJzsmZpNode = (data: any) => {
      jzsmZpNode.value = data
    }

    // 存储从哪个页面跳转到整理端
    const savePrePage = (data: string) => {
      prePage.value = data
    }

    return {
      count,
      userList,
      userInfo,
      breadData,
      nodeTreeData,
      jzsmDbmNode,
      jzsmZpNode,
      zjNode,
      fjNode,
      prePage,
      saveUserInfo,
      saveBreadData,
      saveNodeTreeData,
      saveJzsmDbmNode,
      saveJzsmZpNode,
      saveZjNode,
      saveFjNode,
      savePrePage,
    }
  },
  {
    // 持久化设置（默认存储sessionStorage，https://seb-l.github.io/pinia-plugin-persist/advanced/partial-state.html）
    persist: { enabled: true },
  },
)
